package homeworks.day04;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * 改错
 * <p>
 * 程序实现的是简易记事本工具。程序启动后向pw.txt文件写内容
 * 用户输入的每一行字符串都写入到文件中，单独输入exit时
 * 程序退出。
 *
 * @author Xiloer
 */
public class Test02 {
    public static void main(String[] args) {
        try (
                FileOutputStream fos = new FileOutputStream("./pw.txt");
                OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
                BufferedWriter bw = new BufferedWriter(osw);
                PrintWriter pw = new PrintWriter(bw, true);
        ) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入：");
            while (true) {
                String str = scanner.nextLine();
                if ("exit".equals(str)){
                    break;
                }
                pw.println(str);
            }

        } catch (IOException e){
            e.printStackTrace();
        }
    }
}
